<?php
namespace app\home\model;
use think\Model;

class MemberAccessModel extends Model
{
	protected $table  = 'qm_member_access';


	/**
	*
	*增加一条访客信息
	**/
	public function addAccessRes($data)
	{
		$res = $this->insertGetId($data);
		return $res;
	}


	/**
	*用户最新的到访人
	*
	**/
	public function getMemberAccess($member_id)
	{
		$info = $this->where('member_id', '=', $member_id)->order('add_time DESC')->find();
		return $info;
	}


	/**
	*
	*
	*最近一条访问别人的信息
	**/
	public function getMemberAccessOthers($member_id)
	{
		$info = $this->where('access_id', '=', $member_id)->order('add_time DESC')->find();
		return $info;
	}



	/**
	*
	*访客列表
	*
	**/
	public function accessList($member_id, $page = 1)
	{
		$limit = 10;
		$keys = ($page - 1) * $limit;
		$list = $this->where('member_id', '=', $member_id)->limit($keys, $limit)->group('access_id')->order('add_time DESC')->select();
		if(!empty($list))
		{
			$list = $list->toArray();
		}
		return $list;
	}
}
